package
{
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	
	import info.Action;
	import info.BAAnimationInfo;
	
	import spine.AnimationStateData;
	import spine.SkeletonData;
	import spine.SkeletonJson;
	import spine.animation.Animation;
	import spine.starling.SkeletonAnimationSprite;
	import spine.starling.StarlingAtlasAttachmentLoader;
	
	import starling.core.Starling;
	import starling.textures.TextureAtlas;

	public class ResourceMgr
	{
		public static var playerLsit:Dictionary=new Dictionary();
		public function ResourceMgr()
		{
		}
		
		public static function addPlayer(baInfo:BAAnimationInfo):void
		{
			playerLsit[baInfo]=createPlayer(baInfo);
			EditorModel.root.addEntityLevel(playerLsit[baInfo]);
			
		}
		
		public static function createPlayer(baInfo:BAAnimationInfo):SkeletonAnimationSprite{
			var displayObject:SkeletonAnimationSprite;
			var _atlas:TextureAtlas = new TextureAtlas(baInfo.texture, baInfo.xml);
			var _json:SkeletonJson = new SkeletonJson(new StarlingAtlasAttachmentLoader(_atlas));
			var _skeletonData:SkeletonData = _json.readSkeletonData(baInfo.json);
			var _stateData:AnimationStateData = new AnimationStateData(_skeletonData);
			displayObject = new SkeletonAnimationSprite(_skeletonData);
			displayObject.setAnimationStateData(_stateData);
			displayObject.setAnimation(Action.STAND01, true);
			Starling.current.juggler.add(displayObject);
			var rect:Rectangle=displayObject.getBounds(displayObject);
			displayObject.x=rect.width;
			displayObject.y=rect.height;

			return displayObject;
		}
		
	}
}